(function(app) {
    app
        .controller("charge_refundCtrl", ["$scope", "myFactory", '$http', '$stateParams', '$state', '$ionicHistory', '$timeout', '$ionicScrollDelegate', function($scope, myFactory, $http, $stateParams, $state, $ionicHistory, $timeout, $ionicScrollDelegate) {
            //参数接收、定义
            var chdrnum01 = $stateParams.chdrnum01;
            var chdrcoy = $stateParams.chdrcoy;
            var pageData = $stateParams.pageData;
            var itemCommonList = $stateParams.itemCommonList;
            var strItemIds = $stateParams.strItemIds;
            var pclist = pageData.pclist; //银行列表，用于前台
            var pclistBack = []; //银行列表，用于JS校验
            var citylist = pageData.citylist; //城市列表
            var beneFlag = false; //账户持有人那里显示权益人的标志，false为不显示
            var user = pageData.user;
            var userType = ""; //	用户类型
            //S2023103027791个人养老年金项目保全系统优化需求 add by huanghk 20231103 start
            var gyFlag = pageData.gyFlag;//个养标识
            var gyBankList = pageData.gyBankList//个养银行;
            //S2023103027791个人养老年金项目保全系统优化需求 add by huanghk 20231103 end

            //绑定信息到页面
            $scope.chdrnum01 = $stateParams.chdrnum01;
            $scope.pageData = $stateParams.pageData;
            $scope.itemList = pageData.itemList;
            $scope.fmtShowTitle = pageData.fmtShowTitle;
            $scope.charge = pageData.charge;
            $scope.account = pageData.account; //续期账户
            $scope.accountFir = pageData.accountFir; //首期缴费账户
            $scope.hbFlag = false; //默认以平常方式统计金额
            $scope.yjFlag = false; //收费时才显示溢缴保费金额信息，平时默认不显示
            $scope.giveRight1 = false; //用于控制续期账户详细信息，显示隐藏部分，默认隐藏
            $scope.giveRight2 = false; //用于控制授权其他用户详细信息，显示隐藏部分，默认隐藏
            $scope.giveRight3 = false; //用于控制首期缴费账户详细信息，显示隐藏部分，默认隐藏
            $scope.divAccountFlag = true; //用于显示选择退款授权模块，当为false时候表示隐藏，默认显示
            $scope.policy = pageData.policy; //获得缓存保单
            $scope.policyData = pageData.policy; //用于保单相应的，那边用的名字为policyData
            $scope.policyData.ptdate01 = myFactory.DateTools($scope.policyData.ptdate01);
            $scope.readFlag = false; //阅读协议标志，默认为false
            var token = sessionStorage.getItem("token");

            //页面定义的一些参数
            var Type = $scope.charge.type;
            var ReceiptAmount = $scope.charge.receiptAmount;
            var itemIds = $scope.charge.itemIds;
            var surname = $scope.policy.surname; //被保人
            var rnName = $scope.policy.rnName;
            var beneClntNum = pageData.beneClntNum.trim();
            var beneName = pageData.beneName; //权益人
            //S2023103027791个人养老年金项目保全系统优化需求 add by huanghk 20231103 start
            var beneIDCard = pageData.beneIDCard;
            var beneIDType = pageData.beneIDType;
            //S2023103027791个人养老年金项目保全系统优化需求 add by huanghk 20231103 end
            var chargeType = "2";
            var itemId = pageData.itemId;
            var beneBankAcctKey = pageData.beneBankAcctKey;
            var policyHolderClntNum = $scope.policy.cownnum01.trim();
            var insurantClntNum = $scope.policy.lifcnum01;

            //S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180729 begin
            var idTypeAndCharge = pageData.idTypeAndCharge;
            var isNewHighRefundFeeFlag = "";
            if (idTypeAndCharge != undefined && idTypeAndCharge != null && idTypeAndCharge != "") {
                isNewHighRefundFeeFlag = idTypeAndCharge.isNewHighRefundFeeFlag;
                console.log("isNewHighRefundFeeFlag=" + isNewHighRefundFeeFlag);
            }
            //S2018051403895_信易通人证合一及活体检测项目需求 add by rqyang 20180729 end
			//S2018122906735移动保全新增变更项目及功能的优化需求-保险计划 add by csf 20200813 start
    		//是否显示应缴金额栏
    		var showchargefund = true;
    		var showchangeFundtopic = false
    		if($scope.itemList.length == 1 && $scope.itemList[0].itemId == '15') {
    			showchargefund = false;
    		}
    		$scope.itemList.forEach( item =>{
    			if(item.itemId =='15'){
    				showchangeFundtopic = true
    			}
    		})
    		//S2018122906735移动保全新增变更项目及功能的优化需求-保险计划 add by csf 20200813 end
            /******************初始操作逻辑化操作逻辑begin**************/
            len = $scope.itemList.length;
            for (var i = 0; i < len; i++) { //如果提交的修改里面包含itemId="55"，那么最后应退金额显示为“以保险合同约定为准”,否则正常显示统计金额
                if ($scope.itemList[i].itemId == "55") {
                    $scope.hbFlag = true;
                }
            }
            if (itemId == "21") {
                //如果当前变更项是部分提取，那么金额提示预计退费金额
                console.log($scope.pageData.fmtShowContent);
                $scope.pageData.fmtShowContent = "预计退费金额（元）";
            }

            //S2019060408807保全退保项目删除预估应退金额需求 add by yangyan 20200213 start
            $scope.payFeeShowFlag = true;
            $scope.refundedShowFlag = false;
            if (itemId == "27") {
                if ('Y' == $scope.pageData.refundedFlag) {
                    $scope.pageData.fmtShowContent = "预估应退金额（元）";
                    $scope.refundedShowFlag = true;
                    $scope.payFeeShowFlag = false;
                }
            }
            //S2019060408807保全退保项目删除预估应退金额需求 add by yangyan 20200213 end

            if ($scope.charge.type == "R") { //收费时才显示溢缴保费金额信息
                $scope.yjFlag = true;
            }

            for (var i = 0; i < pclist.length; i++) { //如果银行中fieldType为I，默认加个星号，在这之前，把原数据保存到pclistBack中
                var a = {
                    bankdesc: pclist[i].bankdesc,
                    bankcode: pclist[i].bankcode
                }
                pclistBack.push(a);
                if (pclist[i].fieldType == "I") {
                    pclist[i].bankdesc = pclist[i].bankdesc + "*"; //要求不确定，先不加星号 ZZQ 2017-08-23     2017-9-8确定加星号是代表银行能进行实时退费
                }
            }
            $scope.pclist = pclist; //处理完毕后绑定到页面


            if (user != null && user != "" && user != undefined) {
                userType = user.userType;
            }

            //如果实际缴费金额为0则不显示账号信息
            var _receipt = $scope.charge.receiptAmount; //	实际金额
            if (_receipt == 0) {
                //	  			divAccount.style.display = "none" ;
                $scope.divAccountFlag = false; //不显示
            }

            //开户城市初始化
            //客户新需求变更，不想初始带出默认值了，取消默认设置   BY ZZQ 2018-2-27
            /*if($("#newCity").val()==""){
	  			$("#newCity").val(citylist[0].citydesc.trim());
				$("#newCityCode").val(citylist[0].citycode.trim());
	  		}*/

            //如果变更项目中包含 39、40、47、43业务，则账户持有者显示权益人
            for (var i = 0; i < itemIds.length; i++) {
                var tmp = parseInt(itemIds[i]);
                if (tmp == 39 || tmp == 40 || tmp == 47 || tmp == 43) {
                    $("#policyholderMsg").hide(); //隐藏显示投保人
                    $("#beneNameMsg").show(); //显示权益人
                    beneFlag = true;
                    break;
                }
            }
            if (beneFlag) { //如果权益人标是true，那么授权其他账户中，户名就显示为是beneClntNum（已经在参数后台得到），否则默认是投保人的编号
                $("#paynum").val(beneClntNum);
            } else {
                $("#paynum").val(policyHolderClntNum);
            }


            //控制是否大于50万[退费总金额大于50万时不能操作下一步按钮]
            //if( userType=="market" ){ //当用户的类型是market的时候，执行以下部分，_receipt是实际金额，已经在上面定义
            //S2018051403895_信易通人证合一及活体检测项目需求 取消原B/A/AA/AAA级营销员对应可受理退费金额20万/30万/40万/50万的限制规则 add by rqyang 20180728 begin
            if ("Y" != isNewHighRefundFeeFlag) { //非身份证
                if (userType == "AG") {
                    var userGrade = user.userGrade;
                    var isOverAmt = false;

                    if (_receipt >= 500000 && userGrade == "3") { //等级为3时，大于50W不能操作
                        isOverAmt = true;
                    }
                    if (_receipt >= 400000 && userGrade == "2") { //等级为2时，大于40W不能操作
                        isOverAmt = true;
                    }
                    if (_receipt >= 300000 && userGrade == "1") { //等级为1时，大于30W不能操作
                        isOverAmt = true;
                    }
                    if (_receipt >= 200000 && userGrade == "B") { //等级为B时，大于20W不能操作
                        isOverAmt = true;
                    }
                    if (isOverAmt) {
                        //	显示提示内容
                        myFactory.alert("", "本次变更的退费金额已超出授权额度，为保证客户资金安全，请客户亲临客服柜台办理。", "info");
                        //	设置[下一步]按钮不可操作  
                        $("#nextChargeRefund").addClass("disabled");
                    }
                }
            }
            //S2018051403895_信易通人证合一及活体检测项目需求 取消原B/A/AA/AAA级营销员对应可受理退费金额20万/30万/40万/50万的限制规则 add by rqyang 20180728 end


            /******************初始操作逻辑化操作逻辑end**************/
            //重新受理
            $scope.renew = function() {
                    myFactory.renew();
                }
                //退出移动保全
            $scope.exit = function() {
                    myFactory.exit();
                }
                //返回上一步
            $scope.goBack = function() {
                    //history.go(-1);
                    //$("#hidenId").hide();
                    myFactory.goBack();
                }
                //客户须知弹窗
            $scope.tipOpen = function() {
                modal('open', 'tip_model', 'overwindowOnChargeRefund');
            }
            $scope.closeTip = function() {
                    modal('close', 'tip_model', 'overwindowOnChargeRefund');
                }
                //页面同意阅读协议复选框部分
            $scope.changeReadFlag = function() {
                    $scope.readFlag = !$scope.readFlag;
                }
                //城市选择弹窗	
            $scope.cityChose = function() {
                modal('open', 'city_model', 'overwindowOnChargeRefund');
            }
            $scope.cityClose = function() {
                    modal('close', 'city_model', 'overwindowOnChargeRefund');
                }
                //保单详情弹窗
            $scope.showPolicyDetail = function() {
                    modal('open', 'policyDetailModelOnChargeRefund', 'overwindowOnChargeRefund', 'policyDetailCloseXOnChargeRefund');
                }
                //保单详情弹窗关闭函数
            $scope.policyDetailCancel = function() {
                    modal('close', 'policyDetailModelOnChargeRefund', 'overwindowOnChargeRefund', 'policyDetailCloseXOnChargeRefund');
                }
                //指定退款授权方式
            $scope.changeGiveRight = function(type) {
                    if (type == "1") { //1-续期账户
					/*S2022012021079-财富E家外围系统支持需求 add by huanghk 20220711 start*/
					$scope.giveRight2 = false;
					$scope.giveRight3 = false;
					if($scope.account!=null && $scope.account.bankcode == "67"){
                    	if($scope.giveRight1 == false){
    						$scope.giveRight1 = true;
    					}
                    	myFactory.alert("", "该银行不支持收退费，请选择其他银行", "info");
                    	$("#s11").attr("checked",false);
                        return false;
                    }
					if($scope.giveRight1 == false){
						$scope.giveRight1 = true;
						$("#accountFlag").val("1");
					}
					/*S2022012021079-财富E家外围系统支持需求 add by huanghk 20220711 end*/
				}else if(type=="3"){//3-首期账户
					/*S2022012021079-财富E家外围系统支持需求 add by huanghk 20220711 start*/
					$scope.giveRight1 = false;
					$scope.giveRight2 = false;
					if($scope.accountFir!=null && $scope.accountFir.bankcode3 == "67"){
						if($scope.giveRight3 == false){
							$scope.giveRight3 = true;
						}
                    	myFactory.alert("", "该银行不支持收退费，请选择其他银行", "info");
                    	$("#s12").attr("checked",false);
                        return false;
                    }
					if($scope.giveRight3 == false){
						$scope.giveRight3 = true;
						$("#accountFlag").val("3");
					}
					/*S2022012021079-财富E家外围系统支持需求 add by huanghk 20220711 end*/
                    } else if (type == "2") { //2-其他账户
                        if ($scope.giveRight2 == false) {
                            $scope.giveRight2 = true;
                            $("#accountFlag").val("2");
                        }
                        $scope.giveRight1 = false;
                        $scope.giveRight3 = false;

                        if (beneFlag == true) { //如果是属于权益人那么户名paynme这只为权益人，并且让paynmeFlag这个隐藏为3
                            $("#paynme").val(beneName);
                            $("#paynme").html(beneName);
                            $("#paynmeFlag").val('3');
                        } else {
                            $("#paynme").val(surname);
                            $("#paynme").html(surname);
                            $("#paynmeFlag").val('1');
                        }
                    }

                    //视图重新计算容器大小 S_Input_20180419 luxueyan add 20180419 处理输入框被输入法隐藏问题
                    //$ionicScrollDelegate.resize();
                }
                //返回上一页
            $scope.goback = function() {
                    myFactory.goBack();
                }
                //改变银行下拉框
            $scope.changeNewBank = function() {
                var options = "";
                options = $("#newBankSelect option:selected");
                console.log(options.text());
                console.log(options.val());
                $scope.newBank = options.text();
            }

            //查找城市方法
            $scope.searchCity = function() {
                    var cityName = $("#searchCityParam").val();
                    $scope.cityList = "";
                    myFactory.loadingShow(); //显示加载圈
                    $timeout(function() { myFactory.loadingHide(); }, 2000);
                    var timestamp = myFactory.getTimetamp();
                    var sfis = "cityName-token-timestamp";
                    var signStr = "cityName=" + encodeURI(cityName) + "&token=" + token + "&timestamp=" + timestamp; //encodeURI(name)
                    var sign = myFactory.hex(signStr);
                    $http({
                        method: 'GET',
                        url: app.domain + 'common/restSearchCity.action',
                        params: { 'cityName': cityName, 'sign': sign, 'sfis': sfis, 'token': token, 'timestamp': timestamp }
                    }).then(function successCallback(response) {
                        if (response.data.success) {
                            $scope.cityList = response.data.data; //绑定到页面
                        }
                    }, function errorCallback(response) {
                        myFactory.alert("", "查询城市失败", "info");
                    });
                }
                //城市选择
            $scope.cityClick = function(cityCode, cityName) {
                $("#newCity").val(cityName.trim());
                $("#newCityCode").val(cityCode.trim());
            }

            /**
             * 只输入整数函授
             */
            $scope.keyNumPress = function() {
                var keyCode = event.keyCode;
                if (keyCode >= 48 && keyCode <= 57) {
                    event.returnValue = true;
                } else {
                    event.returnValue = false;
                }
            }


            $scope.nextStep = function() {
                    //总体控制标志，只有为true时候才能进行下一步
                    var isAllowNext = false;
                    //定义账号检测所需要的参数，在不同的方法里面填装
                    var params;

                    //如果实际缴费金额为0，那么标志为false，这时候不需要填写退费授权，直接可以跳过校验执行下一步
                    if ($scope.divAccountFlag == false) {
                        isAllowNext = true;
                        toNextPage(isAllowNext);
                    } else {
                        //如果没有同意协议，不给下一步
                        if ($scope.readFlag == false) {
                            myFactory.alert("", "请阅读并同意《保险款项转账取款授权客户须知》", "info");
                            return;
                        }
                        //S2019111110714-移动保全、官微官网保全系统优化需求 add by csf 20200729 start
                        var refundBankName = "";
                        //S2019111110714-移动保全、官微官网保全系统优化需求 add by csf 20200729 end

                        var accountFlag = $("#accountFlag").val().trim();
                        //如果没有选择退费授权方式，则提示
                        if (accountFlag == "") {
                            myFactory.alert("", "请选择续期账号、首期缴费账号或授权其他账号。", "info");
                            return;
                        }

                        //如果改动里面包括item55，那么只允许首期转账退费
                        //S2023103027791个人养老年金项目保全系统优化需求 add by huanghk 20231109 start
                        if (itemIds.indexOf("55") > -1 && accountFlag != 3 && $scope.accountFir!=null && $scope.accountFir.bankcode3.trim() != "") {
                        //S2023103027791个人养老年金项目保全系统优化需求 add by huanghk 20231109 end
                            //myFactory.alert("","犹豫期退保只接受首期转账银行退费，请重新确认！","info");
                            myFactory.alert("", "犹豫期退保只接受首期账户退费，请重新选择！", "info");
                            return;
                        }


                        /**
                         * 选择续期账户方式
                         */
                        if (accountFlag != "" && accountFlag == "1") {

                            var bankcode1 = $scope.account.bankcode.trim(); //	续期银行代码
                            var bankacctkey1 = $scope.account.bankacctkey.trim(); //	续期银行账号
                            //var beneBankAcctKey = pageData.beneBankAcctKey //受益人银行账号，这里不需要再定义，已经在上面得到


                            if (bankcode1 == "") {
                                myFactory.alert("", "续期账号为空。", "info");
                                return;
                            }
                            //	生存给付确认
                            if (itemIds.indexOf("39") > -1) {
                                if (beneBankAcctKey != bankacctkey1) {
                                    myFactory.alert("", "续期账号持有人非生存金/年金/祝寿金受益人，请提供生存金/年金/祝寿金受益人账号进行退费", "info");
                                    return;
                                }
                            }
                            //	生存给付资料变更
                            if (itemIds.indexOf("40") > -1) {
                                if (beneBankAcctKey != bankacctkey1) {
                                    myFactory.alert("", "续期账号持有人非生存金受益人，请提供生存金受益人账号进行退费", "info");
                                    return;
                                }
                            }


                            //var beneClntNum ;	//权益人客户号（受益人）客户号，参数已经在上面定义
                            var paynum1 = $scope.account.paynum.trim(); //	续期账户客户号
                            //var policyHolderClntNum ; //投保人，参数已经在上面定义
                            /*********** 检测权益人客户号 ******
                             * 1. 存在权益人客户号（既不为空值时）
                             * 2. 权益人客户号是否等于续期账户客户号
                             **/
                            if (beneClntNum != "" && beneClntNum != paynum1) {
                                myFactory.alert("", "续期账号与权益人不为同一人。", "info");
                                return;
                            }

                            if (beneClntNum == "" && policyHolderClntNum != paynum1) {
                                myFactory.alert("", "续期账号与投保人不为同一人。", "info");
                                return;
                            }
                            //S2019111110714-移动保全、官微官网保全系统优化需求 add by csf 20200729 start
                            var refundBankName = $scope.account.bankdesc.trim();
                            //S2019111110714-移动保全、官微官网保全系统优化需求 add by csf 20200729 end
                            /**
                            var ret = true;
						
                            var param = {'bankcode':$('#bankcode1').val()};
                            jQuery.ajax({
                            	type:"post",
                            	url:basePath+"/charge/chkBank.action",
                            	data:param,
                            	async:false,
                            	dataType:"JSON",
                            	success:function(data){
                            		if(data == "fail"){
                            			$("#xuzhi").testRemind("续期账号银行不能办理，谢谢！");
                            			ret =  false;
                            		}
                            	}
                            });
                            return ret;
                            **/
                        }
                        /**
                         * 首期缴费账户方式
                         */
                        else if (accountFlag !== "" && accountFlag == "3") {
                            var bankcode3 = $scope.accountFir.bankcode3.trim(); //	首期银行代码
                            var bankacctkey3 = $scope.accountFir.bankacctkey3.trim(); //	首期银行账号
                            //var beneBankAcctKey = pageData.beneBankAcctKey //受益人银行账号，这里不需要再定义，已经在上面得到

                            if (bankcode3 == "") {
                                myFactory.alert("", "首期缴费账号为空。", "info");
                                return;
                            }
                            //	生存给付确认
                            if (itemIds.indexOf("39") > -1) {
                                if (beneBankAcctKey != bankacctkey3) {
                                    myFactory.alert("", "首期缴费账号持有人非生存金/年金/祝寿金受益人，请提供生存金/年金/祝寿金受益人账号进行退费", "info");
                                    return;
                                }
                            }
                            //	生存给付资料变更
                            if (itemIds.indexOf("40") > -1) {
                                if (beneBankAcctKey != bankacctkey3) {
                                    myFactory.alert("", "首期缴费账号持有人非生存金受益人，请提供生存金受益人账号进行退费", "info");
                                    return;
                                }
                            }


                            //var beneClntNum;	//	权益人客户号（受益人）客户号
                            var paynum3 = $scope.accountFir.paynum3.trim(); //	首期账户客户号
                            //var policyHolderClntNum ;投保人  参数已经在上面定义
                            /*********** 检测权益人客户号 ******
                             * 1. 存在权益人客户号（既不为空值时）
                             * 2. 权益人客户号是否等于续期账户客户号
                             **/
                            if (itemIds.indexOf("55") == -1 && beneClntNum != "" && beneClntNum != paynum3) {
                                myFactory.alert("", "首期缴费账号与权益人不为同一人。", "info");
                                return;
                            }

                            if (itemIds.indexOf("55") == -1 && beneClntNum == "" && policyHolderClntNum != paynum3) {
                                myFactory.alert("", "首期缴费账号与投保人不为同一人。", "info");
                                return;
                            }
                            //S2019111110714-移动保全、官微官网保全系统优化需求 add by csf 20200729 start
                            var refundBankName = $scope.accountFir.bankdesc3.trim();
                            //S2019111110714-移动保全、官微官网保全系统优化需求 add by csf 20200729 end
                            /**
                            var ret = true;
                            var param = {'bankcode':$('#bankcode3').val()};
                            jQuery.ajax({
                            	type:"post",
                            	url:basePath+"/charge/chkBank.action",
                            	data:param,
                            	async:false,
                            	dataType:"JSON",
                            	success:function(data){
                            		if(data == "fail"){
                            			$("#xuzhi").testRemind("首期缴费账号银行不能办理，谢谢！");
                            			ret =  false;
                            		}
                            	}
                            });
						
                            if(!ret){
                            	return ret;
                            }**/

                            var ret = true;
                            //var paynum3 = $('#paynum3').val().trim();		//	首期客户号
                            var _city = $scope.accountFir.city3.trim(); //	银行开户城市代码
                            var _paynmeFlag = "3"; //	客户类型[1-投保人,2-被保人,3-受益人]
                            var _flag = "Y"; //	是否建账号[Y-是,N-否]

                            var timestamp = myFactory.getTimetamp();
                            var sfis = "bankcode-bankacctkey-paynmeFlag-flag-beneClntNum-token-timestamp";
                            var signStr = 'bankcode=' + bankcode3 + '&bankacctkey=' + bankacctkey3 + '&paynmeFlag=' + _paynmeFlag + '&flag=' + _flag + '&beneClntNum=' + paynum3 + "&token=" + token + "&timestamp=" + timestamp; //encodeURI(name)
                            var sign = myFactory.hex(signStr);
                            params = { 'bankcode': bankcode3, 'bankacctkey': bankacctkey3, 'city': _city, 'paynmeFlag': _paynmeFlag, 'flag': _flag, 'beneClntNum': paynum3, 'sign': sign, 'sfis': sfis, 'token': token, 'timestamp': timestamp };

                            //			        在这里就提交的话会存在异步问题，统一提取到下面再做操作
                            //			        $http({
                            //						method: 'GET',
                            //						url: app.domain + '/charge/restCheck.action',
                            //						params: {'bankcode':bankcode3,'bankacctkey':bankacctkey3,'city':_city,'paynmeFlag':_paynmeFlag,'flag':_flag,'beneClntNum':paynum3 }
                            //					}).then(function successCallback(response) {
                            //						if (response.data.success) {
                            //							var message = response.data.data.message;
                            //							if(message == "fail"){
                            //								myFactory.alert("","客户录入账号已被其它客户占用，请返回重新确认账号是否有误，如确认无误，请联系您的服务营销员或亲自来我司办理相关变更申请，办理时需提供你的存折卡复印件或开户证明文件，谢谢！","info");
                            //								return;
                            //							}
                            //						}
                            //					}, function errorCallback(response) {
                            //						myFactory.alert("","进行客户录入账号检测查询时发生错误，请返回重试","info");
                            //					});
                            //			        
                            //			        isAllowNext = true;  //校验通过，设置标志
                        }
                        /**
                         * 授权其他银行账户
                         */
                        else if (accountFlag != "" && accountFlag == "2") {
                            var options = "";
                            options = $("#newBankSelect option:selected");
                            var bankcode = options.val();

                            var banKName = $("#newBank").val(); //银行名称
                            var cityCode = $("#newCityCode").val(); //城市代码
                            var bankacctkey = $("#bankacctkey").val(); //	银行账号
                            bankacctkey = bankacctkey.replace(/\s+/g, "");
                            if (bankacctkey == "") {
                                myFactory.alert("", "请输入银行账号", "info");
                                return;
                            } else {
                                var item;
                                var flag = false;
                                for (var i = 0; i < bankacctkey.length; i++) {
                                    item = bankacctkey.charAt(i);
                                    if (isNaN(item)) { //item为非数字
                                        flag = true;
                                    }
                                }
                                if (flag == true) {
                                    myFactory.alert("", "银行账号/卡号请输入数字！", "info");
                                    return;
                                }
                            }

                            if (banKName == undefined || banKName == null || banKName == "") {
                                myFactory.alert("", "请选择开户银行", "info");
                                return;
                            }

                            //不再需要再次确认字段
                            //						var bankacctkeyCon = $("#bankacctkeyCon").val();
                            //						if(bankacctkeyCon == ""){
                            //							myFactory.alert("","请输入确认账号。","info");
                            //							return;
                            //						}else{
                            //							var item;
                            //				        	var flag=false;
                            //				        	for(var i=0;i<bankacctkeyCon.length;i++){
                            //				        		item=bankacctkeyCon.charAt(i);    
                            //				        		if(isNaN(item)){//item为非数字
                            //				        			flag=true;
                            //				        		}	
                            //				        	}
                            //				        	if(flag==true){
                            //				        		myFactory.alert("","确认银行账号/卡号请输入数字！","info");
                            //				        		return;
                            //				        	}
                            //						}
                            //						if(bankacctkey != bankacctkeyCon){
                            //							myFactory.alert("","银行账号/卡号账号不一致。","info");
                            //							return;
                            //						}

                            if (cityCode == "") {
                                myFactory.alert("", "请选择开户城市", "info");
                                return;
                            }

                            var ret = false;
                            //					var acctCheckFlag = false; 	//	是否有账号检测操作[false-没有,true-有]
                            var _beneClntNum = beneClntNum; //	受益人客户号（生存金受益人的客户号）
                            var _bankcode = bankcode; //	银行代码
                            var _city = $("#newCityCode").val(); //	银行开户城市代码
                            var _paynmeFlag = $("#paynmeFlag").val(); //	客户类型[1-投保人,2-被保人,3-受益人]
                            var _flag = "Y"; //	是否建账号[Y-是,N-否]

                            var timestamp = myFactory.getTimetamp();
                            var sfis = "bankcode-bankacctkey-paynmeFlag-flag-beneClntNum-token-timestamp";
                            var signStr = 'bankcode=' + _bankcode + '&bankacctkey=' + bankacctkey + '&paynmeFlag=' + _paynmeFlag + '&flag=' + _flag + '&beneClntNum=' + _beneClntNum + "&token=" + token + "&timestamp=" + timestamp; //encodeURI(name)
                            var sign = myFactory.hex(signStr);
                            params = { 'bankcode': _bankcode, 'bankacctkey': bankacctkey, 'city': _city, 'paynmeFlag': _paynmeFlag, 'flag': _flag, 'beneClntNum': _beneClntNum, 'sign': sign, 'sfis': sfis, 'token': token, 'timestamp': timestamp };

                            //			                       在这里就提交的话会存在异步问题，统一提取到下面再做操作
                            //			        $http({
                            //						method: 'GET',
                            //						url: app.domain + '/charge/restCheck.action',
                            //						params: {'bankcode':_bankcode,'bankacctkey':bankacctkey,'city':_city,'paynmeFlag':_paynmeFlag,'flag':_flag,'beneClntNum':_beneClntNum }
                            //					}).then(function successCallback(response) {
                            //						if (response.data.success) {
                            //							var message = response.data.data.message;
                            //							if(message == "fail"){
                            //								myFactory.alert("","客户录入账号已被其它客户占用，请返回重新确认账号是否有误，如确认无误，请联系您的服务营销员或亲自来我司办理相关变更申请，办理时需提供你的存折卡复印件或开户证明文件，谢谢！","info");
                            //								return;
                            //							}
                            //						}
                            //					}, function errorCallback(response) {
                            //						网路不顺畅时提示(没有进入后台的"账号检测"逻辑)
                            //						myFactory.alert("","请确认当前网路是否顺畅或重新提交数据！","info");
                            //					});
                        }
                        //S2019111110714-移动保全、官微官网保全系统优化需求 add by csf 20200729 start
                        if (accountFlag == "3" || accountFlag == "1") {
                            if (refundBankName == "中信联名信用卡") {
                                myFactory.alert("", "该账户不可用于变更退费，请选择其他银行账户。", "info");
                                myFactory.loadingHide();
                                return;
                            }
                        }
                        //S2019111110714-移动保全、官微官网保全系统优化需求 add by csf 20200729 end
                        //处理完分支校验，对于金额不为零时，来到这里进入一个提交后台总校验，方式1不需要提交后台校验，直接跳下个页面
                        if (accountFlag != "" && accountFlag == "1") {
							//S2023103027791个人养老年金项目保全系统优化需求 add by huanghk 20231113 start
							if(gyFlag=="Y"){
								gyContract();
							}else{
								isAllowNext = true;
								toNextPage(isAllowNext);	
							}
                            //S2023103027791个人养老年金项目保全系统优化需求 add by huanghk 20231113 end
                        } else if ((accountFlag != "" && accountFlag == "3") || (accountFlag != "" && accountFlag == "2")) {
                            $http({
                                method: 'GET',
                                url: app.domain + '/charge/restCheck.action',
                                params: params
                            }).then(function successCallback(response) {
                                if (response.data.success) {
                                    var message = response.data.data.message;
                                    if (message == "fail") {
                                        //myFactory.alert("","客户录入账号已被其它客户占用，请返回重新确认账号是否有误，如确认无误，请联系您的服务营销员或亲自来我司办理相关变更申请，办理时需提供你的存折卡复印件或开户证明文件，谢谢！","info");
                                        myFactory.alert("", "客户录入账号已被其他客户占用，请重新确认账号是否有误，如确认无误，请通过书面形式办理本次申请，办理时需提供您的存折卡复印件或开户证明文件。", "info");
                                        return;
                                    } else {
                                        //S2023103027791个人养老年金项目保全系统优化需求 add by huanghk 20231113 start
										if(gyFlag=="Y"){
											gyContract();
										}else{
											isAllowNext = true;
											toNextPage(isAllowNext);	
										}
			                            //S2023103027791个人养老年金项目保全系统优化需求 add by huanghk 20231113 end
                                    }
                                }
                            }, function errorCallback(response) {
                                //网路不顺畅时提示(没有进入后台的"账号检测"逻辑)
                                myFactory.alert("", "请确认当前网路是否顺畅或重新提交数据！", "info");
                            });
                        }
                    } //这层括号是分类金额是否为0时候的分支，第315行				
                } //这层括号是nextStep()的结尾

            //封装数据提交后台，准备跳转下一个页面的函数
            function toNextPage(isAllowNext) {
                //isAllowNext==false时什么都不操作
                if (isAllowNext == true) {
                    //符合条件，跳转到查阅界面 
                    //封装、处理数据
                    var bankacctkey = $("#bankacctkey").val();
                    bankacctkey = bankacctkey.replace(/\s+/g, "");
                    //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 start
					/*移动保全问题反馈-保单选择退费账户为续期，却上传了其它银行卡影像件 add by huanghk 20221010 start*/
					var accountFlag = $("#accountFlag").val().trim();
					var bankCardItems = {
						bankAccNum:bankacctkey,
						accountFlag:accountFlag
					}
					if(accountFlag=="2" && $scope.bankCardNum == bankacctkey){
						bankCardItems['bigPic'] = $scope.bigPic;
					}
					/*移动保全问题反馈-保单选择退费账户为续期，却上传了其它银行卡影像件 add by huanghk 20221010 end*/
                    var timestamp = myFactory.getTimetamp();
                    var sfis = "token-timestamp";
                    var signStr = "token=" + token + "&timestamp=" + timestamp; //encodeURI(name)
                    var sign = myFactory.hex(signStr);
                    $http({
                        method: 'POST',
                        url: app.domain + 'img/saveBankCardCache.action',
                        data: { paramsMap: bankCardItems, 'sign': sign, 'sfis': sfis, 'token': token, 'timestamp': timestamp }
                    }).then(function successCallback(response) {
                        if (response.data.success) {
                            console.log("saveBankCardCache ok");
                        }
                    }, function errorCallback(response) {
                        console.log("saveIdCardCache error");
                    });

                    //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 end
                    var pageData2 = {
                        "accountFlag": $("#accountFlag").val().trim(),
                        "bankacctkey": bankacctkey,
                        "bankacctkey1": $("#bankacctkey1").val().trim(),
                        "bankacctkey3": $("#bankacctkey3").val().trim(),
                        "bankacctkeyCon": $("#bankacctkey").val().trim(),
                        "bankcode": $("#newBankSelect option:selected").val().trim(),
                        "bankcode1": $("#bankcode1").val().trim(),
                        "bankcode3": $("#bankcode3").val().trim(),
                        "bankdesc": $("#newBankSelect option:selected").text().trim(),
                        "bankdesc1": $("#bankdesc1").val().trim(),
                        "bankdesc3": $("#bankdesc3").val().trim(),
                        "beneClntNum": beneClntNum,
                        "chargeType": chargeType,
                        "city": $("#newCityCode").val().trim(),
                        "city1": $("#city1").val().trim(),
                        "city3": $("#city3").val().trim(),
                        "citydesc": $("#newCity").val().trim(),
                        "citydesc1": $("#citydesc1").val().trim(),
                        "citydesc3": $("#citydesc3").val().trim(),
                        "itemIds": itemIds,
                        "paynme": $("#paynme").val().trim(),
                        "paynme1": $("#paynme1").val().trim(),
                        "paynme3": $("#paynme3").val().trim(),
                        "paynmeFlag": $("#paynmeFlag").val().trim(),
                        "paynum": $("#paynum").val().trim(),
                        "paynum1": $("#paynum1").val().trim(),
                        "paynum3": $("#paynum3").val().trim(),
                        "receiptAmount": ReceiptAmount,
                        "type": Type
                    }

                    $scope.pageData = $stateParams.pageData;

                    $ionicHistory.clearCache().then(function() {
                        $state.go('charge_refund_preview', {
                            itemId: itemId,
                            chdrnum01: chdrnum01,
                            chdrcoy: chdrcoy,
                            pageData: $scope.pageData,
                            pageData2: pageData2,
                            itemCommonList: itemCommonList,
                            strItemIds: strItemIds
                        });
                    })
                }
            }
            
            //S2023103027791个人养老年金项目保全系统优化需求 add by huanghk 20231113 start
            function gyContract(){
				var bankCode = "";
				var accountFlag = $("#accountFlag").val().trim();
				if(accountFlag=="1" || accountFlag=="3"){
					if(accountFlag=="1"){
						bankCode = $("#bankcode1").val().trim(); //续期银行代码
					}else{
						bankCode = $("#bankcode3").val().trim();//首期银行代码
					}
				}else if(accountFlag=="2"){
					bankCode = $("#newBankSelect option:selected").val().trim();
				}
				var gyBank = false;
				for (var i = 0; i < gyBankList.length; i++) {
					if(gyBankList[i].bandcode==bankCode){
						gyBank = true;
						break;
					}
                }
                if(!gyBank){
					myFactory.alert("", "个人养老保单，仅可选择个人养老金银行账户！", "info");
                    myFactory.loadingHide();
                    return;
				}
				myFactory.goBankContract(bankSuccess, bankError);
			}
            
            function bankSuccess(response) {
                var resCode = response.data.returnCode;
                if (resCode == '0') {
                    contract();
                } else {
                    isAllowNext = true;
					toNextPage(isAllowNext);
                }
            }

            function bankError(response) {
                myFactory.alert("", "获取签约开关异常，请稍后重试", "info");
                myFactory.loadingHide();
                return;
            }
            
            var accountFlag = "";
			var accountNo;//账户号
			var accountName;//账户名
			var accountType = '00'; //银行卡类型，默认为银行卡
			var bankCode;
			var bankNames; //银行名称
			var phoneNum = $scope.policyData.mobilphone;
			var code = ''; //验证码
            var signMode = '02'; //请求类型
            var cntbranch = $scope.policyData.chdrcoy + $scope.policyData.cntbranch; //当前保单号所属的机构
            var idType;
            var id;
            var vailddate = ''; //信用卡的有效期
			var cvv2 = ''; //信用卡的CVV2编号
			var sigleLimitAmount='0';
			var dayLimitAmount='0';
			var monthLimitAmount='0';
			var dueDate = "2099-12-31";
			var paymentTimes = 0; //缴费次数
            var paymentDeadline = ''; //缴费截止日
            var agreePayCompanyCode;   
            var authorizedAmt = '999999999'; //授权总金额
            var paymentTimes = 0; //缴费次数
            var paymentDeadline = ''; //缴费截止日
            var currentAmount; //单笔授权金额的最低限制
            function contract() {
				accountFlag = $("#accountFlag").val().trim();
				if(accountFlag=="1" || accountFlag=="3"){
					if(accountFlag=="1"){
						bankCode = $("#bankcode1").val().trim(); //续期银行代码
                    	accountNo = $("#bankacctkey1").val().trim(); //续期银行账号
                    	accountName = $('#paynme1').val().trim();
                    	bankNames = $('#bankdesc1').val().trim()
					}else{
						bankCode = $("#bankcode3").val().trim();//首期银行代码
						accountNo = $("#bankacctkey3").val().trim(); //首期银行账号
						accountName = $('#paynme3').val().trim();
						bankNames = $('#bankdesc3').val().trim();
					}
					idType = $scope.policyData.roleflag35; //证件类型
                	id = $scope.policyData.secuityno; //证件号
                	if (accountName == $scope.policyData.rnName && $scope.policyData.surname != $scope.policyData.rnName) {
                    	idType = $scope.policyData.rnrolefag35; //证件类型
                    	id = $scope.policyData.rnIdNumber; //证件号码
                    }
				}else if(accountFlag=="2"){
					bankCode = $("#newBankSelect option:selected").val().trim();
					accountNo = $("#bankacctkey").val().trim();
					accountName = $('#paynme').val().trim();
					bankNames = $("#newBank").val();
					if(beneFlag){
						idType = beneIDType; //证件类型
                    	id = beneIDCard; //证件号码
					}else{
						idType = $scope.policyData.roleflag35; //证件类型
                        id = $scope.policyData.secuityno; //证件号
					}
				}
				
				for (var i = 0; i < gyBankList.length; i++) {
					if(gyBankList[i].bandcode==bankCode){
						sigleLimitAmount = gyBankList[i].amount;
						dayLimitAmount = gyBankList[i].amount;
						monthLimitAmount = gyBankList[i].amount;
						break;
					}
                }
             	
                console.log("该保单的所属机构是：" + cntbranch);
                console.log("sigleLimitAmount：" + sigleLimitAmount);
                myFactory.goContract(accountNo, accountName, accountType, bankCode, phoneNum, code, signMode, '1', 
                	cntbranch, pageData.fmtFactFeeTotal, idType, id,vailddate, cvv2, sigleLimitAmount, dayLimitAmount,
                	monthLimitAmount, dueDate, successCall, errorCall,chdrnum01, itemId, paymentTimes, paymentDeadline,
                	 '0','','','','','','');
            }
            
            //查询签约接口成功回调
            function successCall(response) {
                myFactory.loadingHide();
                //查询是否签约的，未签约需要跳转到签约界面，并且传入相应参数
                var resCode = response.data.resultCode;
                agreePayCompanyCode = response.data.paymentChannel;
                if (resCode === 'R07') {
                	//被保险人为未成年人,授权人签名取投保人的名称
        			var birthday = $scope.policyData.rnBirthday + "";
                    var tempdate = birthday.substr(0, 4) + "-" + birthday.substr(4, 2) + "-" + birthday.substr(6, 2);
                    var age = getAge(tempdate);
                    var bankAccountName = accountName;
                    if (age < 18) {
                        bankAccountName = $scope.policyData.surname + "";
                    }
        			
                    //要签约，跳转到签约界面

                    //符合条件，跳转到查阅界面 
                    //封装、处理数据
                    var bankacctkey = $("#bankacctkey").val();
                    bankacctkey = bankacctkey.replace(/\s+/g, "");

                    var nextAction = "charge_refund_preview";
                    var pageData2 = {
                        "accountFlag": $("#accountFlag").val().trim(),
                        "bankacctkey": bankacctkey,
                        "bankacctkey1": $("#bankacctkey1").val().trim(),
                        "bankacctkey3": $("#bankacctkey3").val().trim(),
                        "bankacctkeyCon": $("#bankacctkey").val().trim(),
                        "bankcode": $("#newBankSelect option:selected").val().trim(),
                        "bankcode1": $("#bankcode1").val().trim(),
                        "bankcode3": $("#bankcode3").val().trim(),
                        "bankdesc": $("#newBankSelect option:selected").text().trim(),
                        "bankdesc1": $("#bankdesc1").val().trim(),
                        "bankdesc3": $("#bankdesc3").val().trim(),
                        "beneClntNum": beneClntNum,
                        "chargeType": chargeType,
                        "city": $("#newCityCode").val().trim(),
                        "city1": $("#city1").val().trim(),
                        "city3": $("#city3").val().trim(),
                        "citydesc": $("#newCity").val().trim(),
                        "citydesc1": $("#citydesc1").val().trim(),
                        "citydesc3": $("#citydesc3").val().trim(),
                        "itemIds": itemIds,
                        "paynme": $("#paynme").val().trim(),
                        "paynme1": $("#paynme1").val().trim(),
                        "paynme3": $("#paynme3").val().trim(),
                        "paynmeFlag": $("#paynmeFlag").val().trim(),
                        "paynum": $("#paynum").val().trim(),
                        "paynum1": $("#paynum1").val().trim(),
                        "paynum3": $("#paynum3").val().trim(),
                        "receiptAmount": ReceiptAmount,
                        "type": Type
                    }

                    $scope.pageData = $stateParams.pageData;
                    var items = {};
                    items['pageData2'] = pageData2;
                    items['pageData'] = $scope.pageData;
                    items['itemCommonList'] = itemCommonList;
                    items['strItemIds'] = strItemIds;
                    items['chdrnum01'] = chdrnum01;
                    items['chdrcoy'] = chdrcoy;
                    myFactory.loadingHide();
                    var contractItem = {
                        itemId: itemId,
                        userName: accountName,
                        accountType: accountType,
                        Bcode: code,
                        signMode: signMode,
                        isReal: '1',
                        branch: cntbranch,
                        idType: idType,
                        idNum: id,
                        accountNo: accountNo,
                        phoneNo: phoneNum,
                        BankName: bankNames,
                        BankCode: bankCode,
                        BankList: $scope.bankList,
                        nextAction: nextAction,
                        items: items,
                        flag: '2',
                        agreePayCompanyCode: agreePayCompanyCode,
                        sigleLimitAmount: sigleLimitAmount, //单日限额
                        dayLimitAmount: dayLimitAmount, //日累计限额
                        monthLimitAmount: monthLimitAmount, //月累计限额
                		bankAccountName:bankAccountName,//授权人签名
                        dueDate: dueDate, //委托日期
                        resultSign: resCode, //签约查询返回码
                        authorizedAmt: authorizedAmt, //授权金额
                        paymentDeadline: paymentDeadline, //缴费截止日期
                        paymentTimes: paymentTimes, //缴费次数
                        currentAmount: currentAmount, //当前期缴保费
                        signMoney: pageData.fmtFactFeeTotal
                    };
                    $ionicHistory.clearCache().then(function() {
	                	$state.go('contract_gy', { contractItem: contractItem });
	                });
                } else if(resCode === 'R06'){
                    isAllowNext = true;
					toNextPage(isAllowNext);
                } else {
                    myFactory.alert("提示", response.data.resultMsg, "info");
                    return;
                }
            }
			
			//查询签约接口失败回调
            function errorCall() {
                myFactory.loadingHide();
                myFactory.alert("", "查询签约失败，请稍后重试", "info");
                return;
            }
			
			function getAge(strBirthday) {
                var returnAge;
                var strBirthdayArr = strBirthday.split("-");
                var birthYear = strBirthdayArr[0];
                var birthMonth = strBirthdayArr[1];
                var birthDay = strBirthdayArr[2];

                d = new Date();
                var nowYear = d.getFullYear();
                var nowMonth = d.getMonth() + 1;
                var nowDay = d.getDate();

                if (nowYear == birthYear) {
                    returnAge = 0; //同年 则为0岁  
                } else {
                    var ageDiff = nowYear - birthYear; //年之差  
                    if (ageDiff > 0) {
                        if (nowMonth == birthMonth) {
                            var dayDiff = nowDay - birthDay; //日之差  
                            if (dayDiff < 0) {
                                returnAge = ageDiff - 1;
                            } else {
                                returnAge = ageDiff;
                            }
                        } else {
                            var monthDiff = nowMonth - birthMonth; //月之差  
                            if (monthDiff < 0) {
                                returnAge = ageDiff - 1;
                            } else {
                                returnAge = ageDiff;
                            }
                        }
                    } else {
                        returnAge = -1; //返回-1 表示出生日期输入错误 晚于今天  
                    }
                }
                return returnAge; //返回周岁年龄  
            }
			//S2023103027791个人养老年金项目保全系统优化需求 add by huanghk 20231113 end

            /**
             * 扫描银行卡信息
             */
            $scope.scanBankCardInfoChargeRefund = function() {
                    //移动端
                    cordova.sino.getBankCardInfo(function(result) {
                        if (result.success) {
                            if (!result.data.exit) {
                                if (appVersion === "IOS") {
                                    if (result.data.ok) {
                                        var cardNumber = result.data.CardNumber; //卡号
                                        var cardInsName = result.data.CardInsName; //领取银行
                                        var bankCardType = result.data.BankCardType; //银行卡类型
                                        //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 start
                                        if (bankCardType.indexOf('贷') >= 0) {
                                            myFactory.alert("", "信用卡账户不允许授权，请选择储蓄卡", "info");
                                            return;
                                        }
                                        //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 end
                                        //alert(CardNumber+","+CardInsName+","+BankCardType);
                                        cardNumber = cardNumber.replace(/ /g, "");
                                        //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 start
                                        $scope.bankCardNum = cardNumber;
                                        $scope.bigPic = result.data.bigPic;
                                        //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 end
                                        $("#bankacctkey").val(cardNumber);
                                        //自动填充开户银行
                                        var flag = false;
                                        for (var i = 0; i < pclistBack.length; i++) {
                                            if (pclistBack[i].bankdesc.indexOf(cardInsName) >= 0) {
                                                $scope.newBankSelect = pclistBack[i].bankcode;
                                                $("#newBankSelect").val(pclistBack[i].bankcode);
                                                $("#newBank").val(pclistBack[i].bankdesc);
                                                flag = true;
                                            }
                                        }
                                        if (!flag) {
                                            //没有扫描识别到银行名称，则通过配置名称进行匹配
                                            var bankName = myFactory.bankNameMatching(cardInsName);
                                            //S2019111110714银行卡识别错误 add by yangyan 20191126 start
                                            if ('' != bankName) {
                                                //S2019111110714银行卡识别错误 add by yangyan 20191126 end
                                                for (var i = 0; i < pclistBack.length; i++) {
                                                    if (pclistBack[i].bankdesc.indexOf(bankName) >= 0) {
                                                        $scope.newBankSelect = pclistBack[i].bankcode;
                                                        $("#newBankSelect").val(pclistBack[i].bankcode);
                                                        $("#newBank").val(pclistBack[i].bankdesc);
                                                        flag = true;
                                                    }
                                                }
                                                //S2019111110714银行卡识别错误 add by yangyan 20191126 start
                                            }
                                            //S2019111110714银行卡识别错误 add by yangyan 20191126 end
                                            if (!flag) {
                                                //S2019111110714银行卡识别错误 add by yangyan 20191126 start
                                                //myFactory.alert("","部分数据已自动填入，但查找不到开户银行，请手动选择开户银行与开户城市","info");
                                                myFactory.alert("", "部分数据已自动填入，但开户银行不在可选银行列表范围", "info");
                                                //S2019111110714银行卡识别错误 add by yangyan 20191126 end
                                            } else {
                                                myFactory.alert("", "部分数据已自动填入，请手动选择开户城市", "info");
                                            }
                                        } else {
                                            myFactory.alert("", "部分数据已自动填入，请手动选择开户城市", "info");
                                        }
                                    }
                                } else {
                                    //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 start

                                    $scope.bigPic = result.data.bigPic;
                                    //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 end
                                    cordova.sino.confirmBankCardInfo(function(result) {
                                        if (result.success) {
                                            if (result.data.ok) {
                                                var cardNumber = result.data.CardNumber; //卡号
                                                var cardInsName = result.data.CardInsName; //领取银行
                                                var bankCardType = result.data.BankCardType; //银行卡类型
                                                //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 start
                                                if (bankCardType.indexOf('贷') >= 0) {
                                                    myFactory.alert("", "信用卡账户不允许授权，请选择储蓄卡", "info");
                                                    return;
                                                }
                                                //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 end
                                                //alert(CardNumber+","+CardInsName+","+BankCardType);
                                                cardNumber = cardNumber.replace(/ /g, "");
                                                //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 start
                                                $scope.bankCardNum = cardNumber;
                                                //S2019012807164 - 信易通OCR识别功能 add by csf 20190412 end

                                                $("#bankacctkey").val(cardNumber);
                                                //自动填充开户银行
                                                var flag = false;
                                                for (var i = 0; i < pclistBack.length; i++) {
                                                    if (pclistBack[i].bankdesc.indexOf(cardInsName) >= 0) {
                                                        $scope.newBankSelect = pclistBack[i].bankcode;
                                                        $("#newBankSelect").val(pclistBack[i].bankcode);
                                                        $("#newBank").val(pclistBack[i].bankdesc);
                                                        flag = true;
                                                    }
                                                }
                                                if (!flag) {
                                                    //没有扫描识别到银行名称，则通过配置名称进行匹配
                                                    var bankName = myFactory.bankNameMatching(cardInsName);
                                                    //S2019111110714银行卡识别错误 add by yangyan 20191126 start
                                                    if ('' != bankName) {
                                                        //S2019111110714银行卡识别错误 add by yangyan 20191126 end
                                                        for (var i = 0; i < pclistBack.length; i++) {
                                                            if (pclistBack[i].bankdesc.indexOf(bankName) >= 0) {
                                                                $scope.newBankSelect = pclistBack[i].bankcode;
                                                                $("#newBankSelect").val(pclistBack[i].bankcode);
                                                                $("#newBank").val(pclistBack[i].bankdesc);
                                                                flag = true;
                                                            }
                                                        }
                                                        //S2019111110714银行卡识别错误 add by yangyan 20191126 start
                                                    }
                                                    //S2019111110714银行卡识别错误 add by yangyan 20191126 end
                                                    if (!flag) {
                                                        //S2019111110714银行卡识别错误 add by yangyan 20191126 start
                                                        //myFactory.alert("","部分数据已自动填入，但查找不到开户银行，请手动选择开户银行与开户城市","info");
                                                        myFactory.alert("", "部分数据已自动填入，但开户银行不在可选银行列表范围", "info");
                                                        //S2019111110714银行卡识别错误 add by yangyan 20191126 end
                                                    } else {
                                                        myFactory.alert("", "部分数据已自动填入，请手动选择开户城市", "info");
                                                    }
                                                } else {
                                                    myFactory.alert("", "部分数据已自动填入，请手动选择开户城市", "info");
                                                }
                                            }
                                        } else {
                                            myFactory.alert('', '扫描银行卡信息失败:' + result.data.errormsg, 'info');
                                        }
                                    }, result.data)
                                }
                            }
                        } else {
                            //sino.alert("扫描银行卡信息失败:"+result.data.errormsg);
                            myFactory.alert('', '扫描银行卡信息失败:' + result.data.errormsg, 'info');
                        }
                    });

                    //PC端开发测试用
                    //				var result = {
                    //					data : {
                    //						CardNumber:"6216678911114523785",
                    //						CardInsName:"中国银行",
                    //						BankCardType:"借记卡",
                    //						ok:true
                    //					}
                    //				};
                    //				if(result.data.ok){
                    //
                    //					/*********************************待开发逻辑代码区域begin**********************************/
                    //					var cardNumber=result.data.CardNumber;//卡号
                    //					var cardInsName=result.data.CardInsName;//领取银行
                    //					var bankCardType=result.data.BankCardType;//银行卡类型
                    //					//alert(CardNumber+","+CardInsName+","+BankCardType);
                    //				    cardNumber = cardNumber.replace(/ /g,"");
                    //				    $("#bankacctkey").val(cardNumber);
                    //					//自动填充开户银行
                    //					var flag = false;
                    //					for(var i=0 ; i<pclistBack.length ; i++){
                    //						if(pclistBack[i].bankdesc.indexOf(cardInsName)>=0){
                    //							$scope.newBankSelect = pclistBack[i].bankcode;
                    //							$("#newBankSelect").val(pclistBack[i].bankcode);
                    //							$("#newBank").val(pclistBack[i].bankdesc);
                    //							flag = true;
                    //						}
                    //					}
                    //					if(!flag){
                    //						myFactory.alert("","部分数据已自动填入，但查找不到领取银行，请手动选择领取银行与开户城市","info");
                    //					}else{
                    //						myFactory.alert("","部分数据已自动填入，请手动选择开户城市","info");
                    //					}
                    //					/*********************************待开发逻辑代码区域end**********************************/
                    //				}

                } //扫描银行卡信息函数END


        }]);

    //保单详情弹窗
    app.directive('infoid', function() {
        return {
            restrict: 'EA', //指明指令在DOM里面以什么形式被声明,EA.表示即可以是元素也可以是属性
            templateUrl: 'html/input/content_base_info.html' + app.clearCache,
            replace: true, //设置解析后，DOM声明的指令是否消失
            link: function(scope, element, attrs) { //链接函数负责注册DOM事件和更新DOM,
                console.log('弹框指令完成');
            }
        }
    });
})(app)